package com.webank.weideagroup2.service.impl;


import com.webank.weideagroup2.bean.Car;
import com.webank.weideagroup2.bean.Record;
import com.webank.weideagroup2.chain.Chain;
import com.webank.weideagroup2.chain.ChainBuilder;
import com.webank.weideagroup2.service.CarService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class CarServiceImpl implements CarService {

    private Chain chain;


    @PostConstruct
    private void init() {
        chain = ChainBuilder.newInstance();
    }


    @Override
    public List<Record> getCarInfo(Car car, int type) throws Exception {
       List<Record> resultBeanList = chain.getRecords(car);

       //根据type得出分类结果
        List<Record> recordList = new ArrayList<>();
        if(type == 0){
            return resultBeanList;
        }

        for (Record record:resultBeanList) {
            if(record.getRecordType() == type){
                recordList.add(record);
            }
        }
        return recordList;

    }

}
